<form action="" method="POST">
<input type="hidden" name="save" value="1" />
<input type="hidden" name="table" value="<?=$_GET["table"]?>" />

<fieldset><legend>Nastavení tabulky</legend>
<table class="forms">
<tr>
    <th>Uživatelský název: </th>
    <td><input type="text" name="set[title]" value="<?=$settings[$_GET["table"]]["title"]?>" style="width: 350px" /></td>
</tr>
<tr>
    <th>Popis tabulky: </th>
    <td><input type="text" name="set[note]" value="<?=$settings[$_GET["table"]]["note"]?>" style="width: 350px" /></td>
</tr>
<tr>
    <th>Zobrazovat tabulku: </th>
    <td>
        <input type="radio" name="set[visible]" value="1" id="set_visible_1" <? if ($settings[$_GET["table"]]["visible"] == 1 OR !isset($settings[$_GET["table"]]["visible"])) echo " checked" ?> /> <label for="set_visible_1">Ano</label><br />
        <input type="radio" name="set[visible]" value="0" id="set_visible_0" <? if ($settings[$_GET["table"]]["visible"] == 0 AND isset($settings[$_GET["table"]]["visible"])) echo " checked" ?> /> <label for="set_visible_0">Ne</label>
    </td>
</tr>
<tr>
    <th>Editovatelná tabulka: </th>
    <td>
        <input type="radio" name="set[editable]" value="1" id="set_editable_1" <? if ($settings[$_GET["table"]]["editable"] == 1 OR !isset($settings[$_GET["table"]]["editable"])) echo " checked" ?> /> <label for="set_editable_1">Možnost editace záznamů</label><br />
        <input type="radio" name="set[editable]" value="0" id="set_editable_0" <? if ($settings[$_GET["table"]]["editable"] == 0 AND isset($settings[$_GET["table"]]["editable"])) echo " checked" ?> /> <label for="set_editable_0">Pouze pro čtení</label>
    </td>
</tr>
<tr>
    <th>Typ tabulky: </th>
    <td>
        <input type="radio" name="set[type]" value="normal" id="set_type_normal" <? if ($settings[$_GET["table"]]["type"] == 'normal' OR !isset($settings[$_GET["table"]]["type"])) echo " checked" ?> /> <label for="set_type_normal">Strukturovaná tabulka (defaultní)</label><br />
        <input type="radio" name="set[type]" value="couple" id="set_type_couple" <? if ($settings[$_GET["table"]]["type"] == 'couple') echo " checked" ?> /> <label for="set_type_couple">Vazební tabulka</label>
    </td>
</tr>
</table>
</fieldset>


<fieldset><legend>Uživatelské nastavení sloupců tabulky</legend>
<table class="forms">
<tr>
    <th class="head" style="text-align: right;">Sloupec</th>
    <th class="head">Uživatelský název</th>
    <th class="head">Popis</th>
    <th class="head"><img src="./templates/icons/eye.png" title="Viditelnost sloupce ve výpisu řádků a při jejich editaci" /></th>
</tr>
<? foreach ($describe as $desc) { ?>
<tr>
    <th style="font-weight: normal; width: 80px"><?=$desc["field"]?>:&nbsp;</th>
    <td><input type="text" name="cols[<?=$desc["field"]?>][title]" value="<?=htmlspecialchars($desc["set_title"])?>" style="width: 140px" /></td>
    <td><input type="text" name="cols[<?=$desc["field"]?>][note]" value="<?=htmlspecialchars($desc["set_note"])?>" style="width: 300px" /></td>
    <td><input type="checkbox" name="cols[<?=$desc["field"]?>][visible]" <? if ($desc["visible"]) echo " checked"?> /></td>
</tr>
<? } ?>
</table>
</fieldset>

<? foreach ($describe as $desc) if ($desc["content_type"] == "enum" OR $desc["content_type"] == "set") { ?>
<fieldset><legend>Uživatelské nastavení výběru hodnot sloupce "<strong><?=$desc["field"]?></strong>"</legend>
<table class="forms">
<? foreach ($desc["options_set"] as $kopt => $opt) { ?>
<tr>
    <th><?=$kopt?>:&nbsp;</th>
    <td>
    <input type="text" name="options[<?=$desc["field"]?>][<?=$kopt?>]" value="<?=htmlspecialchars($opt)?>" style="width: 140px" />
    </td>
</tr>
<? } ?>
</table>
</fieldset>
<? } ?>

<? foreach ($describe as $desc) if($desc["forkey"]) { ?>
<fieldset><legend>Nastavení cizího klíče "<strong><?=$desc["field"]?></strong>"</legend>
    Tvar zobrazení klíče: <input type="text" name="forkeys[<?=$desc["field"];?>]" id="forkey_<?=$desc["field"];?>" value="<?=$desc["forkey_string"];?>" style="width: 400px" /><br /><br />
    Vložit hodnotu z tabulky <?=$desc["forkey"]["remote_table"]?>:<br />
    <? $keys = $GLOBALS["db"]->loadDescribe($desc["forkey"]["remote_table"]); foreach ($keys as $key) { ?>
    <input type="button" name="butt_forkey_<?=$key["field"];?>" value="<? if (!empty($key["set_title"])) echo htmlspecialchars($key["set_title"]); else echo htmlspecialchars($key["field"]);?>" onclick="document.getElementById('forkey_<?=$desc["field"];?>').value = document.getElementById('forkey_<?=$desc["field"];?>').value + ' [<?=$key["field"]?>]' " />
    <? } unset($keys); ?>
</fieldset>
<? } ?>

<fieldset><legend>Pokročilé nastavení tvaru zobrazení hodnot</legend>
<table class="forms">
<tr>
    <th class="head" style="text-align: right;">Sloupec</th>
    <th class="head">Vzor zobrazení</th>
</tr>
<? foreach ($describe as $desc) if (!$desc["forkey"]) { ?>
<tr>
    <th style="font-weight: normal; width: 80px"><?=$desc["field"]?>:&nbsp;</th>
    <td><input type="text" name="cols[<?=$desc["field"]?>][pattern]" value="<?=htmlspecialchars($desc["pattern"])?>" style="width: 400px" /></td>
</tr>
<? } ?>
</table>
<em>* Zástupný znak pro hodnotu buňky je </em><strong>#</strong> <em>(sharp)</em>
</fieldset>

<div id="footerbox">
    <button type="submit">Uložit</button>
    <button onclick="if (confirm('Opravdu zrušit editaci?')) parent.parent.GB_CURRENT.hide(); return false;">Stornovat</button>
</div>
</form>
